#!/usr/bin/env python

import wx
import resource as r
import __contacts as contacts

class Contacts(wx.Panel):
    '''Contacts class
    
    @author Julot <andy.julot@gmail.com>
    @since Wednesday, February 22, 2012. 09:53 AM'''
    
    def __init__(self, parent):
        super(Contacts, self).__init__(parent)
        
        spacer = r.dimen.spacer
        
        self.splitter = wx.SplitterWindow(self, style=wx.SP_LIVE_UPDATE)
        self.splitter.SetMinimumPaneSize(100)
        
        leftPanel = wx.Panel(self.splitter)
        
        self.filter = wx.SearchCtrl(leftPanel, style=wx.TE_PROCESS_ENTER)
        self.filter.ShowCancelButton(True)
        self.names = contacts.Names(leftPanel)
        
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.filter, 0, wx.GROW)
        sizer.AddSpacer(1)
        sizer.Add(self.names, 1, wx.GROW)
        leftPanel.SetSizer(sizer)
        
        style = wx.BORDER_THEME | wx.TAB_TRAVERSAL
        rightPanel = wx.Panel(self.splitter, style=style)
        
        self.toolBar = contacts.ToolBar(rightPanel)
        self.form = contacts.Form(rightPanel)
        
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.toolBar, 0, wx.GROW)
        sizer.Add(self.form, 1, wx.GROW | wx.ALL, border=spacer)
        
        rightPanel.SetSizer(sizer)
        
        self.splitter.SplitVertically(leftPanel, rightPanel)
        
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.splitter, 1, wx.GROW)
        self.SetSizer(sizer)
        
        self.bind()
        
    def bind(self):
        self.Bind(wx.EVT_TEXT, self._onNameText, self.form.name)
    
    def _onNameText(self, event):
        self.toolBar.save.enable(bool(event.String))        

